import Taro, { redirectTo, setNavigationBarTitle } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { AtIcon, AtForm, AtButton, AtInput } from 'taro-ui'
import React, { useState, useEffect } from 'react'

import api from '../../utils/api'
import request from '../../utils/request'
import { useAsyncEffect } from '../../utils/index'

import IconContract from '../../images/icon-contract.png'
import IconDocument from '../../images/icon-document.png'
import IconDownload from '../../images/icon-download.png'

import './ca.less'

function CA() {
  useEffect(() => {
    try {
      setNavigationBarTitle({
        title: 'CA认证'
      })
      request(api.userInfo, 'GET').then(res => {
        let data = res.member
        console.log(data)
        setName(data.real_name)
        setIdNumber(data.id_card)
        setBankNumber(data.bank_number)
        setPhone(data.bank_phone)
      })
    } catch (error) {
      Taro.showToast({
        title: '获取用户信息失败',
        icon: 'none'
      })
    }
  }, [])

  const [userInfo, setUserInfo] = useState({})

  const [name, setName] = useState('')
  const [idNumber, setIdNumber] = useState('')
  const [bankNumber, setBankNumber] = useState('')
  const [phone, setPhone] = useState('')

  const handleNameChange = (val) => {
    setName(val)
  }
  const handleIdNumberChange = (val) => {
    setIdNumber(val)
  }
  const handleBankNumberChange = (val) => {
    setBankNumber(val)
  }
  const handlePhoneChange = (val) => {
    setPhone(val)
  }
  const onSubmit = () => {
    let data = {
      name,
      idNumber,
      bankNumber,
      phone
    }
    console.log(data)
  }
  return (
    <View className='ca'>
      <View className='layout'>
        <View className='bg'></View>
        <View className='top'></View>
        <View className='cell-group group'>
          <AtForm>
            <View className='row'>
              <AtInput
                name='name'
                type='text'
                className='input'
                title='真实姓名'
                placeholder='请输入真实姓名'
                value={name}
                onChange={handleNameChange}
              />
            </View>
            <View className='row'>
              <AtInput
                name='idNumber'
                type='text'
                className='input'
                title='身份证号'
                placeholder='请输入身份证号'
                value={idNumber}
                onChange={handleIdNumberChange}
              />
            </View>
          </AtForm>
        </View>
        {/* <AtButton className='btn' disabled circle type='primary' onClick={onSubmit}>证书已申请</AtButton> */}
      </View>
    </View>
  )
}

export default CA
